package cn.com.aiton.educenter.service.impl;

import cn.com.aiton.educenter.entity.UcenterMemberWorktype;
import cn.com.aiton.educenter.mapper.UcenterMemberWorktypeMapper;
import cn.com.aiton.educenter.service.UcenterMemberWorktypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 用户的业务类型 服务实现类
 * </p>
 *
 * @author testAuthor
 * @since 2021-05-11
 */
@Service
public class UcenterMemberWorktypeServiceImpl extends ServiceImpl<UcenterMemberWorktypeMapper, UcenterMemberWorktype> implements UcenterMemberWorktypeService {

    @Override
    public boolean init(String userId) {
        UcenterMemberWorktype umw = new UcenterMemberWorktype();
        umw.setWorkType("通用作业");
        umw.setMemberId(userId);
        //调用service的方法实现查询所有的操作
        //构建条件
        QueryWrapper<UcenterMemberWorktype> wrapper = new QueryWrapper<>();
        // 多条件组合查询
        // mybatis学过 动态sql
        if(!StringUtils.isEmpty(userId)) {
            wrapper.eq("member_id",userId);
        }
        wrapper.eq("work_type",umw.getWorkType());
        int countOther = baseMapper.selectCount(wrapper);
        if (!(countOther>=1))
            this.save(umw);



////////////////////////////////////////////////////////////////
        UcenterMemberWorktype umw1 = new UcenterMemberWorktype();
        umw1.setWorkType("视频作业");
        umw1.setMemberId(userId);
        //调用service的方法实现查询所有的操作
        //构建条件
        QueryWrapper<UcenterMemberWorktype> wrapper1 = new QueryWrapper<>();
        // 多条件组合查询
        // mybatis学过 动态sql

        if(!StringUtils.isEmpty(userId)) {
            wrapper1.eq("member_id",userId);
        }
        wrapper1.eq("work_type",umw1.getWorkType());
        int countVideo = baseMapper.selectCount(wrapper1);
        if (!(countVideo>=1))
            this.save(umw1);

        return true;
    }
}
